
import os
import glob
import openpyxl
from datetime import datetime
from openpyxl.styles import Alignment

def wirteSheetHeader(sheet):
    sheet.cell(1, 1, "ID")

def read_files_in_directory(directory):
    file_list = []
    for filename in os.listdir(directory):
        if os.path.isfile(os.path.join(directory, filename)):
            file_list.append(filename)
    return file_list

def get_aosp_ids(dir, suffix):
    py_files = []
    for root, dirs, files in os.walk(dir):  # 遍历所有目录，包括自身
        for file in files:  # 遍历文件，抓取指定文件
            pre, suf = os.path.splitext(file)
            if suf == suffix:
                f = open(os.path.join(root, file),'r')
                lines = f.readlines()
                for lines in lines:
                    if "SYSTEM_" in lines:
                         py_files.append(os.path.join(file).split('.')[0])
    return py_files

if __name__ == "__main__":
    directory = '../../../vhal_platform/common'  # 替换为实际的目录
    file_extension = '.cpp'

    cpp_files = get_aosp_ids(directory,".cpp")

    excle = openpyxl.load_workbook("Aosp_ID.xlsx")
    sheetNames = excle.sheetnames
    for sheet in sheetNames:
        excle.remove(excle[sheet])

    sheet = excle.create_sheet("AospID")
    wirteSheetHeader(sheet)
    sheetColumns=['A']
    for sheet_column in sheetColumns:
        dimensions = sheet.column_dimensions[sheet_column]
        if sheet_column == 'A':
            dimensions.width = 60

    index = 2
    # 创建新的内容
    for prop in cpp_files:
        sheet.cell(index, 1, prop)
        index += 1
    excle.save("Aosp_ID.xlsx")